/*
 * Copyright (C), 2014-2015, 联创车盟汽车服务有限公司
 * FileName: UserManageController.java
 * Author:   ryan
 * Date:     2015年2月2日 上午9:44:33
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>    <time>    <version>    <desc>
 * 修改人姓名        修改时间        版本号        描述
 */
package com.linkage.controller.background;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.linkage.interceptor.NeedAdminLogin;
import com.linkage.interceptor.NeedLogin;
import com.linkage.service.auth.AdminLoginService;

/**
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author ryan
 *
 */

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminLoginService adminLoginService;

    
    /**
     * 后台管理首页
     *
     * @return
     */
    @NeedAdminLogin
    @RequestMapping(value = "", method = RequestMethod.GET)
    public String adminPage() {
        return "background/admin";
    }


    /**
     * 进入后台登录页面
     *
     * @return
     */
    @RequestMapping(value = "/adminlogin", method = RequestMethod.GET)
    public String adminLogin() {
        return "background/login";
    }
    

    /**
     * 登录操作
     *
     * @return
     */
    @RequestMapping(value = "/doAdminLogin", method = RequestMethod.POST)
    public String adminlogin(@RequestParam("loginName") String loginName, @RequestParam("password") String password,
            HttpServletRequest request, Model model) {
        String errorMsg= this.adminLoginService.adminLogin(request, password, loginName);

        if ("".equals(errorMsg)) {
            return "redirect:";
        } else {
            model.addAttribute("errorMsg", errorMsg);
            return "background/login";
        }
    }


    @RequestMapping(value = "/adminlogout", method = RequestMethod.GET)
    @NeedAdminLogin
    public String adminlogout(HttpServletRequest request) {
        this.adminLoginService.logout(request);
        return "redirect:/admin/adminlogin";
    }
    
    
    
    
}

